package com.scalesoft.artsync.plugins;

import java.util.prefs.Preferences;

import com.scalesoft.artsync.plugins.util.Log;


public abstract class BasicAccountSettings implements AccountSettings {

	private String username;
	private String password;
	private Preferences prefs;

	public BasicAccountSettings() {
		super();
	}

	@Override
	public String getPassword() {
		return password;
	}

	@Override
	public String getUsername() {
		return username;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Override
	public void saveSettings(String username, String password) {
		Log.d(this, "Saving settings for user " + username);
		String serviceName = getServiceName();
		prefs = Preferences.userRoot().node("/artsync/"+serviceName);
		prefs.put("username", username);
		prefs.put("password", password);
	}

	@Override
	public void loadSettings() {
		String serviceName = getServiceName();
		prefs = Preferences.userRoot().node("/artsync/"+serviceName);
		this.username = prefs.get("username", "");
		this.password = prefs.get("password", "");
		Log.d(this, "Loading settings for user " + this.username);
	}

	protected abstract String getServiceName();

}